package controller

import (
	"net/http"

	"core/service"

	"core/entity"

	"github.com/gin-gonic/gin"
)

func WorkflowCreate(c *gin.Context) {
	var workflow entity.Workflow

	err := c.BindJSON(&workflow)
	if err != nil {
		SendError(c, err)
		return
	}

	err = service.CreateWorkflow(workflow)

	if err != nil {
		SendError(c, err)
		return
	}
	SendData(c, workflow)
}

func WorkflowRetrieve(c *gin.Context) {
	var workflows []entity.Workflow
	var err error

	workflows, err = service.ListWorkflows()

	if err != nil {
		SendError(c, err)
		return
	}
	SendData(c, workflows)
}

func WorkflowUpdate(c *gin.Context) {
	c.String(http.StatusOK, "hello world!")
}

func WorkflowDelete(c *gin.Context) {
	c.String(http.StatusOK, "hello world!")
}

func WorkflowRegister(r *gin.Engine) {
	r.POST("/workflow", WorkflowCreate)
	r.GET("/workflow", WorkflowRetrieve)
	r.PUT("/workflow", WorkflowUpdate)
	r.DELETE("/workflow", WorkflowDelete)
}
